package chapter18;


/**
 * @Author：xz
 * @Date：2023/9/11
 */
/**
 *   Object 给的默认的 toString() 源码
 *     public String toString() {
 *         return getClass().getName() + "@" + Integer.toHexString(hashCode());
 *     }
 */
public class Test01 {
    public static void main(String[] args) {
        Books book = new Books(1L,"张三");
        String b1 = book.toString();
        // Object的toString方法输出 类名@地址  (重写toString()之前)
        System.out.println(b1); // chapter18.Books@2f0e140b
        // 重写toString()之后  ，输出引用的时候会自动调用该引用的toStirng()
        System.out.println(book); // id：1；name：张三

    }
}

class Books {
    private Long id;

    private String name;

    public Books() {

    }

    public Books (Long id, String name) {
        this.id = id;
        this.name = name;
    }

//    @Override
//    public String toString() {
//       return "id：" + this.id + "；" + "name：" + this.name;
//    }
}
